#==============================================================================
# Theta Scripting Engine - Job Auto-States by privateer
#==============================================================================
# ► Version  : 1.0
#==============================================================================
# ► Introduction
# This script lets you add Auto-States to classes in your game. So, for example,
# a Monk class will grant its bearer "Evade Magick", and so on.
#==============================================================================
# ► Instruction
# Just put this script anywhere below Scene_Debug but above Main.
#==============================================================================
# ► Compatibility
# Designed and tested for the default class change system. (That means through
# the event call "Change Actor Class" or actor.class_id = )
# May or not work with scripts that alter how class change is done.
#==============================================================================

module TSE
  module JobAutoStates
    ############################################################################
    # JOB_AUTOSTATES
    ############################################################################
    # Format : X => [Y, Y, ...],
    # X : Any valid Class ID.
    # Y : Any valid State ID(s) that will be given to unit who uses class ID X.
    JOB_AUTOSTATES = {
    1 => [16], # Class ID will give state 2,3,4 to its bearer.
    }
  end
end

#==============================================================================
# DON'T EDIT ANY FURTHER UNLESS YOU KNOW WHAT YOU'RE DOING!
#==============================================================================

$imported = {} if $imported.nil?
$imported["TSE-JobAutoStates"] = true

class RPG::Class
  include TSE
  include JobAutoStates
  def job_autostates
    JOB_AUTOSTATES.has_key?(id) ? JOB_AUTOSTATES[id] : []
  end
end

class Game_Actor < Game_Battler
  alias tse_job_autostates_setup setup
  def setup(actor_id)
    tse_job_autostates_setup(actor_id)
    unless $data_classes[@class_id].job_autostates.empty?
      for state in $data_classes[@class_id].job_autostates
        add_state(state, true)
      end
    end
  end
  alias tse_job_autostates_class_id= class_id=
  def class_id=(class_id)
    old_class_ja = $data_classes[self.class_id].job_autostates
    new_class_ja = $data_classes[class_id].job_autostates
    unless old_class_ja.empty?
      for state in @states
        if old_class_ja.include?(state)
          remove_state(state, true) unless new_class_ja.include?(state)
        end
      end
    end
    unless new_class_ja.empty?
      for state in new_class_ja
        add_state(state, true)
      end
    end
    tse_job_autostates_class_id=(class_id)
  end
end
